home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / libraries / newiff.lha / NewIFF / NewIFF39.lha / newiff39 / modules / getdisplay.c < prev    next >
C/C++ Source or Header  |  1993-09-28  |  6KB  |  251 lines

  1.  
  2. /*----------------------------------------------------------------------*
  3.  * GETDISPLAY.C  Support routines for reading/displaying ILBM files.
  4.  * (IFF is Interchange Format File.)
  5.  *
  6.  * Based on code by Jerry Morrison and Steve Shaw, Electronic Arts.
  7.  * This software is in the public domain.
  8.  * Modified for iffparse.library by CBM 04/90
  9.  * This version for the Commodore-Amiga computer.
  10.  *
  11.  * 37.9  04/92 - use vp->ColorMap->Count instead of MAXAMCOLORREG
  12.  * 37.10 07/92 - use scr->RastPort.BitMap instead of &scr->BitMap
  13.  *                      for future compatibility
  14.  * 39.1  07/92 - add support for V39 color loading
  15.  * 39.10 08/93 - add maxdisplaydepth() function (use instead of MAXAMDEPTH)
  16.  *----------------------------------------------------------------------*/
  17. #define INTUI_V36_NAMES_ONLY
  18.  
  19. #include "iffp/ilbm.h"
  20. #include "iffp/packer.h"
  21. #include "iffp/ilbmapp.h"
  22.  
  23. extern struct Library *GfxBase;
  24.  
  25. /* showilbm
  26.  *
  27.  * Passed an ILBMInfo initilized with with a not-in-use ParseInfo.iff
  28.  *   IFFHandle and desired propchks, collectchks, stopchks, and a filename,
  29.  *   will load and display an ILBM, initializing ilbm->Bmhd, ilbm->camg,
  30.  *   ilbm->scr, ilbm->win, ilbm->vp, ilbm->srp, ilbm->wrp,
  31.  *   ilbm->colortable, and ilbm->ncolors.
  32.  *
  33.  *   Note that ncolors may be more colors than you can LoadRGB4.
  34.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if you
  35.  *   change the colors yourself using 1.3/2.0 functions.
  36.  *
  37.  * V39 - unless ilbm->IFFPFlags & IFFPF_NOCOLOR32, will do 32-bit
  38.  *   color load under V39 and higher
  39.  *
  40.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  41.  */
  42.  
  43. LONG showilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  44. {
  45. LONG error = 0L;
  46.  
  47.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  48.  
  49.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  50.     {
  51.     D(bug("showilbm: openifile successful\n"));
  52.  
  53.     error = parseifile((struct ParseInfo *)ilbm,
  54.                 ID_FORM, ID_ILBM,
  55.                 ilbm->ParseInfo.propchks,
  56.                 ilbm->ParseInfo.collectchks,
  57.                 ilbm->ParseInfo.stopchks);
  58.  
  59.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  60.         {
  61.         D(bug("showilbm: parseifile successful\n"));
  62.  
  63.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  64.         {
  65.             if(error = createdisplay(ilbm))
  66.             {
  67.             deletedisplay(ilbm);
  68.             }
  69.         }
  70.         else
  71.         {
  72.         message(SI(MSG_ILBM_NOILBM));
  73.         error = NOFILE;
  74.         }
  75.         }
  76.     if(error)    closeifile((struct ParseInfo *)ilbm);
  77.     }
  78.     return(error);
  79. }
  80.  
  81.  
  82. /* unshowilbm
  83.  *
  84.  * frees and closes everything alloc'd/opened by showilbm
  85.  * returns BOOL Success under V36 and above, always TRUE under <V36
  86.  */
  87. BOOL unshowilbm(struct ILBMInfo *ilbm)
  88. {
  89.     if(deletedisplay(ilbm))
  90.         {
  91.         closeifile((struct ParseInfo *)ilbm);
  92.         return(TRUE);
  93.         }
  94.     else return(FALSE);
  95. }
  96.  
  97.  
  98.  
  99. /* createdisplay
  100.  *
  101.  * Passed a initialized ILBMInfo with parsed IFFHandle (chunks parsed,
  102.  * stopped at BODY),
  103.  * opens/allocs the display and colortable, and displays the ILBM.
  104.  *
  105.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  106.  *   ilbm->vp,  ilbm->wrp, ilbm->srp and also ilbm->colortable and
  107.  *   ilbm->ncolors.
  108.  *
  109.  * Note that ncolors may be more colors than you can LoadRGB4.
  110.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if you
  111.  *   change the colors yourself using 1.3/2.0 functions.
  112.  *
  113.  * V39 - unless ilbm->IFFPFlags & IFFPF_NOCOLOR32, will do 32-bit
  114.  *   color load under V39 and higher
  115.  *
  116.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  117.  */
  118.  
  119. LONG createdisplay(struct ILBMInfo *ilbm)
  120.     {
  121.     LONG error;
  122.  
  123.     D(bug("createdisplay:\n"));
  124.  
  125.     error             = getdisplay(ilbm);
  126.  
  127.     D(bug("createdisplay: after getdisplay, error = %ld\n", error));
  128.  
  129.     if(!error) 
  130.         error     = loadbody(ilbm->ParseInfo.iff,
  131.                     ilbm->scr->RastPort.BitMap,&ilbm->Bmhd);
  132.  
  133.     D(bug("createdisplay: after loadbody, error = %ld\n", error));
  134.  
  135.     if(!error)
  136.         { 
  137.         if(!(getcolors(ilbm)))    setcolors(ilbm,ilbm->vp);
  138.         }
  139.     if(error)  deletedisplay(ilbm);
  140.     return(error);
  141.     }
  142.  
  143.  
  144. /* deletedisplay
  145.  *
  146.  * closes and deallocates created display and colors
  147.  * returns BOOL Success under V36 and above, always TRUE under <V36
  148.  */
  149. BOOL deletedisplay(struct ILBMInfo *ilbm)
  150.     {
  151.     if(freedisplay(ilbm))
  152.         {
  153.         freecolors(ilbm);
  154.         return(TRUE);
  155.         }
  156.     else return(FALSE);
  157.     }
  158.  
  159.  
  160.  
  161. /* getdisplay
  162.  *
  163.  * Passed an initialized ILBMInfo with a parsed IFFHandle (chunks parsed,
  164.  * stopped at BODY),
  165.  * gets the dimensions and mode for the display and calls the external
  166.  * routine opendisplay().  Our opendisplay() is in the screen.c
  167.  * module.  It opens a 2.0 or 1.3, ECS or non-ECS screen and window.
  168.  * It also does 2.0 overscan centering based on the closest user prefs.
  169.  *
  170.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  171.  *   ilbm->vp, ilbm->wrp, ilbm->srp
  172.  *
  173.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  174.  */
  175. LONG getdisplay(struct ILBMInfo *ilbm)
  176.     {
  177.     struct IFFHandle *iff;
  178.     BitMapHeader *bmhd;
  179.     ULONG                modeid;
  180.     UWORD                wide, high, deep, maxdepth;
  181.  
  182.  
  183.     if(!(iff=ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  184.  
  185.     if(!(bmhd = (BitMapHeader *)findpropdata(iff, ID_ILBM, ID_BMHD)))
  186.         {
  187.         message (SI(MSG_ILBM_NOBMHD));
  188.         return(IFFERR_SYNTAX);
  189.         }
  190.  
  191.     *(&ilbm->Bmhd)    = *bmhd;
  192.  
  193.     ilbm->camg = modeid = getcamg(ilbm);
  194.  
  195.         wide = (RowBytes(bmhd->w)) >= (RowBytes(bmhd->pageWidth)) ?
  196.                 bmhd->w : bmhd->pageWidth;
  197.         high = MAX(bmhd->h, bmhd->pageHeight);
  198.     maxdepth = maxdisplaydepth(modeid);
  199.         deep = MIN(bmhd->nPlanes,maxdepth);
  200.  
  201.  
  202.     /*
  203.      * Open the display
  204.      */
  205.     if(!(opendisplay(ilbm,wide,high,deep,modeid)))
  206.         {
  207.         message(SI(MSG_ILBM_NODISPLAY));
  208.         return(1);
  209.         }
  210.     return(0);
  211.     }
  212.  
  213.  
  214. /* freedisplay
  215.  *
  216.  * closes and deallocates display from getdisplay (not colors)
  217.  * returns BOOL Success under V36 and above, always TRUE under <V36
  218.  */
  219. BOOL freedisplay(struct ILBMInfo *ilbm)
  220.     {
  221.     return(closedisplay(ilbm));
  222.     }
  223.  
  224.  
  225. /* maxdisplaydepth
  226.  *
  227.  * Returns maximum display depth for specified display mode id
  228.  */
  229. UWORD maxdisplaydepth(ULONG displayid)
  230.     {
  231.     extern struct Library *GfxBase;
  232.         DisplayInfoHandle displayhandle;
  233.         struct DimensionInfo dimensioninfo;
  234.     UWORD maxdepth = MAXAMDEPTH;
  235.  
  236.     if(GfxBase->lib_Version >= 37)
  237.         {
  238.             if(displayhandle=FindDisplayInfo(displayid))
  239.         {
  240.         if(GetDisplayInfoData(displayhandle,
  241.             (UBYTE *)&dimensioninfo,
  242.                 sizeof(struct DimensionInfo),
  243.             DTAG_DIMS,NULL))
  244.             {
  245.             maxdepth=dimensioninfo.MaxDepth;
  246.             }
  247.         }
  248.         }
  249.     return(maxdepth);
  250.     }
  251.